home *** CD-ROM | disk | FTP | other *** search
- package sun.net.www.protocol.http;
-
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.io.PrintStream;
- import java.net.URL;
- import sun.net.ProgressData;
- import sun.net.www.MessageHeader;
- import sun.net.www.MeteredStream;
- import sun.net.www.URLConnection;
- import sun.net.www.http.AuthenticationInfo;
- import sun.net.www.http.HttpClient;
-
- public class HttpURLConnection extends URLConnection {
- static final String EOL = "\r\n";
- static final String version = System.getProperty("java.version");
- public static final String userAgent;
- static final String acceptString = "Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2\r\n";
- static final int maxRedirections = 5;
- HttpClient http;
- Handler handler;
- InputStream inputStream;
- boolean outputStreamOpen = false;
-
- HttpURLConnection(URL var1, Handler var2) {
- super(var1);
- this.handler = var2;
- }
-
- public HttpURLConnection(URL var1, String var2, int var3) {
- super(var1);
- this.handler = new Handler(var2, var3);
- }
-
- public void connect() throws IOException {
- if (!super.connected) {
- super.connected = true;
- ProgressData.pdata.register(super.url);
- this.http = null;
-
- try {
- if (super.url.getProtocol().equals("https")) {
- throw new IOException("https not supported for this version.");
- }
-
- this.http = new HttpClient(super.url, this.handler.proxy, this.handler.proxyPort);
- } catch (Throwable var2) {
- if (this.http != null) {
- this.http.closeServer();
- }
-
- ProgressData.pdata.unregister(super.url);
- if (var2 instanceof SecurityException) {
- throw (SecurityException)var2;
- }
-
- throw var2 instanceof IOException ? (IOException)var2 : new IOException(var2.toString());
- }
-
- if (this.http == null) {
- throw new IOException("Couldn't connect to " + super.url.toExternalForm());
- }
- }
- }
-
- private static AuthenticationInfo getAuthentication(URL var0, String var1, String var2) {
- return null;
- }
-
- public OutputStream getOutputStream() throws IOException {
- String var1 = ((java.net.URLConnection)this).getRequestProperty("content-type");
- this.connect();
- if (this.inputStream != null) {
- throw new IOException("Cannot write output after reading input.");
- } else if (this.outputStreamOpen) {
- throw new IOException("Cannot open output twice.");
- } else {
- HttpClient var2 = this.http;
- PrintStream var5 = var2.serverOutput;
- this.outputStreamOpen = true;
- PrintStream var3 = new PrintStream(var5);
- String var4 = "POST " + this.http.getURLFile(super.url) + " HTTP/1.0" + "\r\n" + userAgent + "Referer: " + super.url + "\r\n" + "Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2\r\n";
- if (var1 == null) {
- var1 = "application/x-www-form-urlencoded";
- }
-
- var4 = var4 + "Content-type: " + var1 + "\r\n";
- var3.print(var4);
- return new HttpPostBufferStream(var5);
- }
- }
-
- public InputStream getInputStream() throws IOException {
- if (this.inputStream != null) {
- return this.inputStream;
- } else {
- int var2 = 0;
-
- while(true) {
- this.connect();
- if (!this.outputStreamOpen) {
- String var3 = "GET " + this.http.getURLFile(super.url) + " HTTP/1.0" + "\r\n" + userAgent + "" + "Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2\r\n" + "\r\n";
- Runtime var4 = Runtime.getRuntime();
- HttpClient var5 = this.http;
- PrintStream var15 = new PrintStream(var4.getLocalizedOutputStream(var5.serverOutput));
- var15.print(var3);
- var15.flush();
- }
-
- try {
- this.http.processRequest(super.url.getFile());
- HttpClient var7 = this.http;
- Object var1 = var7.serverInput;
- var7 = this.http;
- String var9 = var7.mimeHeader != null ? var7.mimeHeader.findValue("location") : null;
- if (var9 != null) {
- if (this.outputStreamOpen) {
- this.http.closeServer();
- super.connected = false;
- this.http = null;
- throw new IOException("Cannot redirect with POST: " + super.url);
- }
-
- ++var2;
- if (var2 > 5) {
- throw new IOException("Too many redirections (" + var2 + "): " + super.url);
- }
-
- ProgressData.pdata.unregister(super.url);
- URL var10 = new URL(super.url, var9);
- super.url = var10;
- if (!"http".equals(super.url.getProtocol())) {
- this.http.closeServer();
- super.connected = false;
- this.http = null;
- throw new IOException("Cannot redirect to other protocol: " + super.url);
- }
-
- ProgressData.pdata.register(super.url);
- }
-
- HttpClient var11 = this.http;
- if (var11.status == 200 || var9 == null) {
- var11 = this.http;
- ((URLConnection)this).setProperties(var11.mimeHeader);
- if (((URLConnection)this).getProperties() == null) {
- ((URLConnection)this).setProperties(new MessageHeader());
- }
-
- var11 = this.http;
- String var14 = var11.mimeHeader != null ? var11.mimeHeader.findValue("content-length") : null;
- int var16 = 0;
- if (var14 != null && (var16 = Integer.parseInt(var14)) != 0) {
- var1 = new MeteredStream((InputStream)var1, var16, super.url);
- } else {
- ProgressData.pdata.unregister(super.url);
- }
-
- this.inputStream = (InputStream)var1;
- return (InputStream)var1;
- }
-
- this.http.closeServer();
- ProgressData.pdata.unregister(super.url);
- this.http = null;
- this.inputStream = null;
- super.connected = false;
- } catch (IOException var6) {
- ProgressData.pdata.unregister(super.url);
- throw var6;
- }
- }
- }
- }
-
- public String getHeaderField(String var1) {
- if (this.http == null) {
- try {
- this.getInputStream();
- } catch (Exception var3) {
- }
- }
-
- HttpClient var2 = this.http;
- return var2.mimeHeader != null ? var2.mimeHeader.findValue(var1) : null;
- }
-
- static {
- userAgent = "User-Agent: " + System.getProperty("http.agent", "Java" + version) + "\r\n";
- }
- }
-